package com.hsnn.medstgmini.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.base.dict.dao.DicHosptypeDao;
import com.hsnn.medstgmini.base.dict.model.DicArea;
import com.hsnn.medstgmini.base.dict.model.DicDrugmaterial;
import com.hsnn.medstgmini.base.dict.model.DicEntProfile;
import com.hsnn.medstgmini.base.dict.model.DicExperttype;
import com.hsnn.medstgmini.base.dict.model.DicHosptype;
import com.hsnn.medstgmini.base.dict.model.DicPhar;
import com.hsnn.medstgmini.base.dict.model.DicSys;
import com.hsnn.medstgmini.dao.DynamicSelectDao;
import com.hsnn.medstgmini.pro.project.model.BidProject;
import com.hsnn.medstgmini.service.DynamicSelectManager;
import com.hsnn.medstgmini.util.SelectForm;

@Service("selecManager")
public class DynamicSelectManagerImpl implements DynamicSelectManager {

	@Autowired
	private DynamicSelectDao selectDao;

	@Autowired
	private DicHosptypeDao hosptypeDao;

	
	@Override
	public List<SelectForm> getOrderStatus(String classifyCode) {
		List<DicSys> list = selectDao.getOrderStatus(classifyCode);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicSys data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getDicCode());
			form.setText(data.getDicName());
			slist.add(form);
		}
		return slist;
	}
	
	@Override
	public List<SelectForm> getArchiveType(String classifyCode) {
		List<DicSys> list = selectDao.getArchiveType(classifyCode);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicSys data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getDicCode());
			form.setText(data.getDicName());
			slist.add(form);
		}
		return slist;
	}
	
	public List<SelectForm> getArea(String fatherId) {
		List<DicArea> list = selectDao.getArea(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicArea data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getAreaid());
			form.setText(data.getAreaname());
			slist.add(form);
		}
		return slist;
	}
	
	@Override
	public List<SelectForm> getQYArea(String fatherId) {
		List<DicArea> list = selectDao.getQYArea(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicArea data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getAreaid());
			form.setText(data.getAreaname());
			slist.add(form);
		}
		return slist;
	}

	public List<SelectForm> getPhar(String fatherId) {
		List<DicPhar> list = selectDao.getPhar(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicPhar data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getPharId());
			form.setText(data.getPharName());
			slist.add(form);
		}
		return slist;
	}

	public List<SelectForm> getForm(String fatherId) {
		List<Object> list = selectDao.getForm(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			Object[] data = (Object[]) list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data[0]==null?"":data[0].toString());
			form.setText(data[1]==null?"":data[1].toString());
			slist.add(form);
		}
		return slist;
	}

	public List<SelectForm> getMaterial(String fatherId) {
		List<DicDrugmaterial> list = selectDao.getMaterial(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicDrugmaterial data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getMaterialId());
			form.setText(data.getMaterialName());
			slist.add(form);
		}
		return slist;
	}

	/**
	 * @category 根据fatherId查询医疗机构类型
	 * @param fatherId
	 * @return
	 */
	public List<SelectForm> getHospType(String fatherId) {
		List<DicHosptype> list = hosptypeDao.getChildList(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicHosptype data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getHospTypeId());
			form.setText(data.getHospType());
			slist.add(form);
		}
		return slist;
	}
	
	/**
	 * @category 根据fatherId查询启用的医疗机构类型
	 * @param fatherId
	 * @return
	 */
	@Override
	public List<SelectForm> getQYHospType(String fatherId) {
		List<DicHosptype> list = hosptypeDao.getQYChildList(fatherId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicHosptype data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getHospTypeId());
			form.setText(data.getHospType());
			slist.add(form);
		}
		return slist;
	}

	@Override
	public List<SelectForm> getDiSys(String ID) {
		List<DicSys> list = selectDao.getDiSys(ID);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			DicSys data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getDicCode());
			form.setText(data.getDicName());
			slist.add(form);
		}
		return slist;
	}
	
	public List<SelectForm> getProject (String ID){
		List <BidProject> list = selectDao.getProject(ID);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			BidProject data = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(data.getProjId());
			form.setText(data.getName());
			slist.add(form);
		}
		return slist;
	}
	public List<SelectForm> getMyProj(String hospCode){
		List<Object[]> list = selectDao.getMyProj(hospCode);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(obj[0]==null?"":obj[0].toString());
			form.setText(obj[1]==null?"":obj[1].toString());
			slist.add(form);
		}
		return slist;
	}
	public List<SelectForm> getCompProj(String compId){
		List<Object[]> list = selectDao.getCompProj(compId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(obj[0]==null?"":obj[0].toString());
			form.setText(obj[1]==null?"":obj[1].toString());
			slist.add(form);
		}
		return slist;
	}
	public List<SelectForm> getProjByProdCompId(String proCompId){
		List<Object[]> list = selectDao.getProjByProdCompId(proCompId);
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(obj[0]==null?"":obj[0].toString());
			form.setText(obj[1]==null?"":obj[1].toString());
			slist.add(form);
		}
		return slist;
	}
	public List<SelectForm> getProj(){
		List<Object[]> list = selectDao.getProj();
		List<SelectForm> slist = new ArrayList<SelectForm>();
		for (int i = 0; i < list.size(); i++) {
			Object[] obj = list.get(i);
			SelectForm form = new SelectForm();
			form.setValue(obj[0]==null?"":obj[0].toString());
			form.setText(obj[1]==null?"":obj[1].toString());
			slist.add(form);
		}
		return slist;
	}

	@Override
	public List<SelectForm> getDicExpertType(String ID,int status) {
		List<DicExperttype> list = selectDao.getExpertType(ID,status);
		List<SelectForm> formList = new ArrayList<SelectForm>();
		for(int i = 0; i < list.size(); i++){
			DicExperttype dicExperttyp = list.get(i);
			SelectForm selectForm = new SelectForm();
			selectForm.setText(dicExperttyp.getExpertTypeName());
			selectForm.setValue(dicExperttyp.getDicExperttypeId());
			formList.add(selectForm);
		}
		return formList;
	}

	/**
	 * 
	 * @category 获取企业资质类型
	 * @author wangbing
	 * @date 2015年6月10日 下午7:06:29
	 * @return
	 */
	@Override
	public List<SelectForm> getProfileType() {
		List<DicEntProfile> list = selectDao.getProfileType();
		List<SelectForm> formList = new ArrayList<SelectForm>();
		for(int i = 0; i < list.size(); i++){
			DicEntProfile dicEntProfile = list.get(i);
			SelectForm selectForm = new SelectForm();
			selectForm.setText(dicEntProfile.getFirstLevelIndiName());
			selectForm.setValue(dicEntProfile.getDicEntProfileId());
			formList.add(selectForm);
		}
		SelectForm selectForm = new SelectForm();
		selectForm.setText("其它");
		selectForm.setValue(UUID.randomUUID().toString());
		formList.add(selectForm);
		return formList;
	}

}
